Hi All,
I've noticed that when I open a file for text read (not binary), when I read the char '\r' from the file, I skip 2 bytes.
In other words whenever I read '\r' I actully read '\r' and '\n'.
Is this behavior is in C ANSI?
Thank you again
Hi All,
I've noticed that when I open a file for text read (not binary), when I read the char '\r' from the file, I skip 2 bytes.
In other words whenever I read '\r' I actully read '\r' and '\n'.
Is this behavior is in C ANSI?
Thank you again
Last edited by salvadoravi; 12-29-2007 at 06:44 AM.
Yes. Whenever the platform's newline sequence of chars is read, it's converted to one '\n' in C. The exception is once you start venturing outside of the C standard library. Also of note, if you try to get a file size using ftell(), you will get the exact size including all of the '\r''s on a Windows machine. If you're allocating a buffer to hold the contents of a text file, then you may not actually need the entire buffer size.